
from fastapi import FastAPI
from fastapi.staticfiles import StaticFiles
from fastapi.openapi.docs import get_swagger_ui_html
import uvicorn
from tortoise.contrib.fastapi import register_tortoise
from config import TORTOISE_ORM
from api_orm.student import router as student_router

app = FastAPI(
    title="FastAPI学习项目",
    description="这是一个用于学习FastAPI的示例项目",
    version="1.0.0",
    docs_url=None,  # 禁用默认的swagger文档
    redoc_url="/redoc"
)

register_tortoise(
    app,
    config=TORTOISE_ORM,
)

# 挂载静态文件目录
app.mount("/static", StaticFiles(directory="static"), name="static")

app.include_router(student_router, prefix="/student")

@app.get("/",
    tags=["根路径"],

    summary="根路径访问",
    description="这是网站的根路径，返回一个简单的欢迎消息",
    response_description="返回包含欢迎消息的JSON对象"
)

@app.get("/docs", include_in_schema=False)
async def custom_swagger_ui_html():
    return get_swagger_ui_html(
        openapi_url=app.openapi_url,
        title=app.title + " - Swagger UI",
        oauth2_redirect_url=app.swagger_ui_oauth2_redirect_url,
        swagger_js_url="/static/swagger-ui-bundle.js",
        swagger_css_url="/static/swagger-ui.css",
    )

if __name__ == "__main__":
    uvicorn.run(
        "main_orm:app", 
        host="127.0.0.1", 
        port=8000, 
        reload=True,
        log_level="debug"
    )
